package com.winning.dps.rda.common.util;


import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * 响应信息主体
 */
public class ResponseEntity extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResponseEntity() {
        put("code", 200);
    }

    public static ResponseEntity error() {

        return error(500, "未知异常，请联系管理员");
    }

    public static ResponseEntity error(String msg) {

        return error(500, msg);
    }

    public static ResponseEntity error(int code, String msg) {
        ResponseEntity re = new ResponseEntity();
        re.put("code", code);
        re.put("msg", msg);
        return re;
    }

    public static ResponseEntity ok(String msg) {
        ResponseEntity re = new ResponseEntity();
        re.put("msg", msg);
        return re;
    }

    public static ResponseEntity ok(Map<String, Object> map) {
        ResponseEntity re = new ResponseEntity();
        map = Optional.ofNullable(map).orElse(new HashMap<>(1));
        re.putAll(map);
        return re;
    }

    public static ResponseEntity ok() {
        return new ResponseEntity();
    }

    public ResponseEntity put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
